package cn.itcast.mapper;

import cn.itcast.domain.Orders;
import cn.itcast.domain.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrdersMapper {
    @Select("select * from orders where user_id = #{uid}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "number",property = "number"),
            @Result(property = "itemsList",javaType = List.class,column = "id",
            many = @Many(select = "cn.itcast.mapper.ItemsMapper.findByOid"))
    })
    List<Orders> findByUid(int uid);

    //查询所有订单信息及用户姓名
    @Select("select * from orders")
    @Results(
            {
                    @Result(id = true,column = "id",property = "id"),
                    @Result(column = "number",property = "number"),
                    @Result(property = "user",javaType = User.class,column = "user_id",
                    one = @One(select = "cn.itcast.mapper.UserMapper.findByOid"))
            }
    )
    List<Orders> findOrders();
}
